package menu;

import java.util.Vector;

import menu.MenuAction.MenuActionType;
import core.actions.Action;
import core.actions.ActionInfo;
import core.actions.ActionMap;

public class MenuController {

	public static void setBrowseMenu(PlayerMenu pm, String actionName){
		ActionMap<MenuAction> newMenu = new ActionMap<MenuAction>();
		pm.setHeaderText("Browse: "+actionName);
		
		newMenu.add(new MenuAction(actionName, "Equip", MenuActionType.EQUIP_STEP_ONE));
		for(ActionInfo ai : pm.getPlayerData().getActionSet().findActionInfo(actionName).getLinkedActions()){
			System.out.println(""+String.valueOf(ai));
			newMenu.add(new MenuAction(ai.getAction().toString(), MenuActionType.BROWSE));
		}
		newMenu.add(new MenuAction("Main", MenuActionType.MAIN));
		pm.setMenuMap(newMenu);
	}
	
	public static void setMainMenu(PlayerMenu pm){
		ActionMap<MenuAction> newMenu = new ActionMap<MenuAction>();
		pm.setHeaderText("Main menu");
		newMenu.add(new MenuAction("Move", "Browse", MenuActionType.BROWSE));
		newMenu.add(new MenuAction("Add radius", MenuActionType.ADD_RADIUS));
		newMenu.add(new MenuAction("Add depth", MenuActionType.ADD_DEPTH));
		newMenu.add(new MenuAction("Default actions", MenuActionType.SET_DEFAULT_ACTION_MAP));
		newMenu.add(new MenuAction("Reduce radius", MenuActionType.REDUCE_RADIUS));
		newMenu.add(new MenuAction("Reduce depth", MenuActionType.REDUCE_DEPTH));
		newMenu.add(new MenuAction("Next Unit", MenuActionType.NEXT_UNIT));
		newMenu.add(new MenuAction("Color", MenuActionType.CHANGE_COLOR));
		pm.setMenuMap(newMenu);
	}
	public static void setEquipPosMenu(PlayerMenu pm, String actionName){
		ActionMap<MenuAction> newMenu = new ActionMap<MenuAction>();
		pm.setHeaderText("Equip "+actionName+" where?");
		ActionMap<Action> currentActionMap = pm.getPlayerData().getActionMap();
		for(int row=0; row<currentActionMap.getRadius(); row++){
			Vector<MenuAction> menuRow = new Vector<MenuAction>();
			for(int col=0; col<currentActionMap.getDepth(); col++){
				String shownName="";
				if(currentActionMap.getActionAcceptNull(row, col) != null){
					shownName=currentActionMap.getActionAcceptNull(row, col).toString();
				}
				MenuAction newMenuAction = new MenuAction(actionName, shownName, MenuActionType.EQUIP_STEP_TWO);
				menuRow.add(newMenuAction);
			}
			newMenu.addPie(menuRow);
		}
		pm.setMenuMap(newMenu);
	}
	
}
